


/*

move next Cstl 	

gen_conscribe_api.php?jsonpcallback=jsonp1323167852468&_=1323218547724&key=daaf7b06638046349f2c33e5698b8e62
&city=22349
&_l=kr
&_p=EW-IPHONE-KR HTTP/1.1

jsonp1323167852468({"code":0,"ret":{"price":1027,"type":3}})
jsonp1323167852472({"code":0,"ret":{"price":372,"type":2,"refresh":2274}})



// drink 

gen_conscribe_api.php?jsonpcallback=jsonp1323167852469&_=1323218548748&key=daaf7b06638046349f2c33e5698b8e62
&city=22349
&action=pub_process
&_l=kr
&_p=EW-IPHONE-KR HTTP/1.1

jsonp1323167852469({"code":0,"ret":
	{"gold":24148,"price":5135,"refresh":3600,"hero":{"gid":117,"p":11,"i":21,"c1":15,"g":2,"c2":295},"rumor":0}})



// hire
gen_conscribe_api.php?jsonpcallback=jsonp1323167852470&_=1323218551376&key=daaf7b06638046349f2c33e5698b8e62
&city=22349&
action=hire_process
&_l=kr
&_p=EW-IPHONE-KR HTTP/1.1

jsonp1323167852470({"code":0,"ret":
	{"gold":19013,
		"hero":{"id":87686,"gid":117,"p":11,"i":21,"c1":15,"f":50,"g":2,"c2":295,"fy":0,"s":0,"e":"10","w":0,"tw":0,"tl":0}}})

*/

var em_hdrin;

CHDrin = function() {
	
	this.class_HDrin = 1;

	this.objName = 'CHDrin: ';
	this.param = {};

	this.actionSeq = new CActionSeq();
	
	// store this ref 
	em_hdrin = this;
	
};


CHDrin.INVALID = 9;


CHDrin.prototype = {

	makeAction: function(act_param) {
		
		var outer = this;
		
		this.action = {
			name: 'HDrin',
			start: this.doHDrin,
			// param: undefined,		// deprecated 
			action_table: [
				{ 
					cmd: 'cnoscribe',
					preAction:  undefined,
					doParam: { citnum: act_param.citnum,  cb : function (data) {
									outer.checkConscribe.call(em_hdrin, data); }
								},
					doFunc:	 'hdrin_conscribe',
					gotResult: undefined,
				},
				{ 
					cmd: 'cons_pub_process!',
					preAction:  undefined,
					doParam: { citnum: act_param.citnum, 'cons_action': 'pub_process', cb : function (data) {
									outer.checkConsPubProcess.call(em_hdrin, data); }
								},
					doFunc:	 'hdrin_action_conscribe',
					gotResult: undefined,		// 
				},		
				],
			done_cb: function(data) { outer.completed(data)	; }			// cb for complete action 
		};
	
		
		this.actionSeq.setAction(this.action);
 },

	// I F  

	start: function(param) {
		this.doHDrin(param);
	},

	completed:	function(data) {
		debug.log( this, 'HDRIn  action completed !!');
		
		this.param.hdrin_cb.fire( { type: 'FIN_CSTL', data: data});
	}, 
	
	// real doing 	
	doHDrin: function (param) {
		 
		$.extend( this.param, param);
		this.makeAction(this.param);
		
		debug.log(this, retName(this) , ' test go ');
		
		this.actionSeq.start();
	},


	checkConscribe: function(data) {
			console.log('================   H Drn,,, got   cons.. ');			

// 				"code":0,"ret":{"price":1027,"type":3}
// {"code":0,"ret":{"price":372,"type":2,"refresh":2274}})
		debug.log(this, 1, data);
		var outer = this;
		if ( data.ret.type == 3 ) {		// OK .. do pub process 
			// noty  action :  go next action 
			setTimeout( function() { outer.actionSeq.next.call(outer.actionSeq); } ,CUtil.RandTime(2000));
			// setTimeout( "outer.actionSeq.next.call(this.actionSeq);" ,CUtil.RandTime(2000));
			return;
		}
		
		
		// else stop action .
		/// notify cb ... 
		this.param.hdrin_cb.fire( {type:'GOT_HDRIN', data: data});
		this.completed();
	},
	
	
	checkConsPubProcess: function(data) {
			console.log('================   H Drn,,, got   checkConsPubProcess. pub action  ');
			debug.log(this, 1, data);
// 	"code":0,"ret":
//	{"gold":24148,"price":5135,"refresh":3600,"hero":{"gid":117,"p":11,"i":21,"c1":15,"g":2,"c2":295},"rumor":0}

		/// notify cb ... 
		this.param.hdrin_cb.fire( {type:'GOT_HDRIN', data: data});
		
		var outer = this;		
		setTimeout( function() { outer.actionSeq.next.call(outer.actionSeq); } ,CUtil.RandTime(2000));		
		return;			
	},	
	
	
};

 

 
